import matplotlib.pyplot as plt
import numpy as np
# labels='frogs','hogs','热狗','logs'
# sizes=15,20,45,10
# colors='yellowgreen','gold','lightskyblue','lightcoral'
# explode=0,0.1,0,0
# plt.rcParams['font.family']=['STFangsong']
# plt.pie(sizes,explode=explode,labels=labels,colors=colors,autopct='%1.1f%%',shadow=True,startangle=50)
# plt.axis('equal')
# plt.show()


#查看系统字体库
# from matplotlib import pyplot as plt
# import matplotlib
# a=sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])

# for i in a:
#     print(i)


# import numpy as np 
# import matplotlib.pyplot as plt 
# x = np.arange(1,11) 
# y =  2  * x +  5 
# plt.rcParams['font.family']=['STFangsong']
# plt.title("Matplotlib demo") 
# plt.xlabel("X轴") 
# plt.ylabel("Y轴") 
# plt.plot(x,y,"*b") 
# plt.show()


#正弦波图
# import numpy as np 
# import matplotlib.pyplot as plt 
# # 计算正弦曲线上点的 x 和 y 坐标
# x = np.arange(0,  3  * np.pi,  0.1) 
# y = np.sin(x)
# plt.title("sine wave form")  
# # 使用 matplotlib 来绘制点
# plt.plot(x, y) 
# plt.show()

#条形图
# import matplotlib.pyplot as plt
# plt.rcParams['font.family']=['STFangsong']
# plt.style.use('ggplot')
# print(plt.style.available)

# customers = ['ABC', 'DEF', 'GHI', 'JKL', 'MNO']
# customers_index = range(len(customers))
# sale_amounts = [127, 90, 201, 111, 232]

# fig = plt.figure()
# ax1 = fig.add_subplot(1,1,1)
# ax1.bar(customers_index, sale_amounts, align='center', color='darkblue')
# ax1.xaxis.set_ticks_position('bottom')
# ax1.yaxis.set_ticks_position('left')

# plt.xticks(customers_index, customers, rotation=0, fontsize='small')
# plt.xlabel("顾客名字")
# plt.ylabel('销售总数')
# plt.title('每位顾客的销售数量')

# plt.savefig('bar_plot.png', dpi=400, bbox_inches='tight')
# plt.show()


# 四图合一
import numpy as np
import matplotlib.pyplot as plt
 
# 获取所有的自带样式
print(plt.style.available)
 
# 使用自带的样式进行美化
plt.style.use("ggplot")
 
fig, axes = plt.subplots(ncols = 2, nrows = 2)
 
# 四个子图的坐标轴赋予四个对象
ax1, ax2, ax3, ax4 = axes.ravel()
 
x, y = np.random.normal(size = (2, 100))
ax1.plot(x, y, "o")
 
x = np.arange(1, 10)
y = np.arange(1, 10)
 
# plt.rcParams['axes.prop_cycle']获取颜色的字典
# 会在这个范围内依次循环
ncolors = len(plt.rcParams['axes.prop_cycle'])
# print ncolors
# print plt.rcParams['axes.prop_cycle']
 
shift = np.linspace(1, 20, ncolors)
for s in shift:
    # print s
    ax2.plot(x, y + s, "-")
 
x = np.arange(5)
y1, y2, y3 = np.random.randint(1, 25, size = (3, 5))
width = 0.25
 
# 柱状图中要显式的指定颜色
ax3.bar(x, y1, width, color = "r")
ax3.bar(x + width, y2, width, color = "g")
ax3.bar(x + 2 * width, y3, width, color = "y")
 
for i, color in enumerate(plt.rcParams['axes.prop_cycle']):
    xy = np.random.normal(size= 2)
    for c in color.values():
        ax4.add_patch(plt.Circle(xy, radius = 0.3, color= c))
 
ax4.axis("equal")
 
plt.show()